package cn.edu.ujn.util;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.HandlerInterceptor;

import cn.edu.ujn.m.User;

public class LoginInterceptor implements HandlerInterceptor {
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		String requestURI=request.getRequestURI();
		if(requestURI.indexOf("/login")>=0) {
			return true;
		}
		HttpSession session=request.getSession();
		User user = (User)session.getAttribute("USER_SESSION");
		if(user!=null)
			return true;
		request.getRequestDispatcher("/WEB-INF/jsp/login.jsp").forward(request, response);
		return false;
		
	}
	

}
